package util;

import org.springframework.ui.Model;
import pojo.Category;
import service.ICategoryService;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 综合的工具类
 */
public class Util {
    /**
     * 获取本周周一的日期
     * @return
     */
    public static Date getMondayDate(){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        int day = calendar.get(Calendar.DAY_OF_WEEK);
        calendar.add(Calendar.DATE, calendar.getFirstDayOfWeek()-day);
        Date time = calendar.getTime();
        return calendar.getTime();
    }
    public static void setGeneralDataForView(ICategoryService categoryService, Model model){
        //获取类别
        List<Category> categories = categoryService.getAllCategory();
        model.addAttribute("categories",categories );
    }
}
